package demo.android.com.mvpdemo.mvp.base;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

/**
 * Created by Vya on 2018/1/4 0004.
 */

public abstract class BaseMvpActivity<P extends BasePresenter> extends AppCompatActivity implements BaseView {

    private P mPresenter;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setViewContent();
        Log.e("wangyan","BaseMvpActivity---->");
        //创建  P,每个子类的P都不一样要交给子类创建
        mPresenter = createPresenter();
        mPresenter.attach(this);
        initView();
        initData();
    }


    protected abstract void setViewContent();
    protected abstract void initView();
    protected abstract void initData();
    protected abstract P createPresenter();


    @Override
    protected void onDestroy() {
        super.onDestroy();
        mPresenter.detach();
    }

    public P getPresenter() {
        return mPresenter;
    }
}
